package com.gzx.bi.modular.screen.mapper;

import com.gzx.bi.modular.screen.entity.GzxStatisticBI;
import com.gzx.bi.modular.screen.vo.GzxStatisticBIVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * bi报表持久层
 *
 * @author xbl
 */
public interface GzxStatisticBIMapper extends BaseMapperPlus<GzxStatisticBI, GzxStatisticBIVo> {

    //获取待合并的数据
    @Select({
            "<script>",
            "select bi_type biType,bi_result biResult,bi_month as biMonth from gzx_statistic_bi " +
                    "where bi_month like concat(#{currentMonth,jdbcType=VARCHAR},'%') " +
                    "and bi_type = #{biType} " +
                    "</script>"
    })
    List<GzxStatisticBI> getMergeData(String currentMonth, String biType);

    //插入数据，存在则更新，不存在则插入
    @Insert({
            "<script>",
            "insert into gzx_statistic_bi(bi_type,bi_result,bi_month) " +
                    "values(#{biType},#{biResult},#{biMonth}) " +
                    "on duplicate key update bi_result = #{biResult},update_time = CURRENT_TIMESTAMP " +
                    "</script>"
    })
    void insertOnDuplicate(GzxStatisticBI bi);

}
